package com.webbei.test;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.ibatis.session.SqlSession;
import org.apache.struts2.ServletActionContext;

import com.webbei.pojo.Carseries;
import com.webbei.pojo.Customer;

public class test {

    public static String encode(String s,String enc){
    	String str = null;
		try {
			str = URLEncoder.encode(s, enc);
		} catch (UnsupportedEncodingException e) {

			e.printStackTrace();
		}finally{
			return str;
		}
    }
    public static String decode(String s,String enc){
    	String str = null;
    	try {
			str = URLDecoder.decode(s,enc);
		} catch (UnsupportedEncodingException e) {

			e.printStackTrace();
		}finally{
			return str;
		}
    }
	private SqlSession session;
	private String username;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setSession(SqlSession session) {
		this.session = session;
	}

	public String execute(){

		Carseries c = (Carseries) session.selectOne("Carseries.getCarseries", 1);
		username = c.getSeriesName();

		return "success";
	}
	public static void testJson(){
		JSONObject json = new JSONObject();
		json.put("one", 1);
		json.put("tow", 2);
		System.out.println(json.toString());
		System.out.println(json.get("one"));

	}
	public static void testJson2(){
		String s = "{one:1,tow:2}";
		JSONObject json = JSONObject.fromObject(s);
		System.out.println(json.toString());
	}

	 public void testMysql() {
		 List<Customer> clist=session.selectList("customer.testProcedure");
		 System.out.println(clist);
    }

	public static void main(String[] args) {
		Map map=ServletActionContext.getContext().getSession();
		map.put("username", "xixiaoming");
		System.out.println(map.get("username"));
	}
}
